package com.zhiwang.planet.mvvm.viewmodel.withdraw

import androidx.lifecycle.MutableLiveData
import androidx.paging.DataSource
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.mvvm.model.entity.main.WithDrawRecord

class WithDrawDataSourceFactory constructor(val restApi: RestApi)
    : DataSource.Factory<Int, WithDrawRecord>() {
    /**
     * Create a DataSource.
     *
     *
     * The DataSource should invalidate itself if the snapshot is no longer valid. If a
     * DataSource becomes invalid, the only way to query more data is to create a new DataSource
     * from the Factory.
     *
     *
     * [LivePagedListBuilder] for example will construct a new PagedList and DataSource
     * when the current DataSource is invalidated, and pass the new PagedList through the
     * `LiveData<PagedList>` to observers.
     *
     * @return the new DataSource.
     *
     */

    val sourceLiveData = MutableLiveData<ItemPagedKeyDataSource>()

    override fun create(): DataSource<Int, WithDrawRecord> {

        val source = ItemPagedKeyDataSource(restApi)
        sourceLiveData.postValue(source)
        return source
    }
}